import { Injectable } from '@angular/core';
import { API } from 'src/api/API';
import { ResultList } from 'src/model/comm/ResultList';
import { YYListInfo } from 'src/model/yy/YYListInfo';
import { ResultPageList } from 'src/model/comm/ResultPageList';
import { YYListReq } from 'src/model/yy/YYListReq';
import { ResultInfo } from 'src/model/comm/ResultInfo';
import { IDReq } from 'src/model/comm/IDReq';
import { YYInfo } from 'src/model/yy/YYInfo';
import { YYCTypeListInfo } from 'src/model/yy/YYCTypeListInfo';
import { YYFilterListReq } from 'src/model/yy/YYFilterListReq';
import { YYModifyRightReq } from 'src/model/yy/YYModifyRightReq';
import { CryptoHelper } from 'src/helper/CryptoHelper';
import { ComHelper } from 'src/helper/comHelper';

@Injectable()
export class YY1API {
  // 构造函数
  constructor(private api: API) {
  }

  // 查询YY1类型
  async queryCType(showLoader: boolean = true): Promise<ResultList<YYCTypeListInfo>> {
    let list = await this.api.get<ResultList<YYCTypeListInfo>>(
      '/api/YY1/QueryCType',
      null,
      showLoader
    );

    // list.lstInfo.forEach(info => {
    //   info.cType = CryptoHelper.decryptAES(info.cType);
    // });

    return list;
  }

  // 查询YY1列表
  async queryList(req: YYListReq, showLoader: boolean = true): Promise<ResultPageList<YYListInfo>> {
    // req.cType = CryptoHelper.encryptAES(req.cType);

    let list = await this.api.get<ResultPageList<YYListInfo>>(
      '/api/YY1/QueryList',
      req,
      showLoader
    );

    // list.lstInfo.forEach(info => {
    //   info.title = CryptoHelper.decryptAES(info.title);
    // });

    return list;
  }

  // 过滤YY1列表
  async filterList(req: YYFilterListReq, showLoader: boolean = true): Promise<ResultPageList<YYListInfo>> {
    // req.title = CryptoHelper.encryptAES(req.title);
    // req.content = CryptoHelper.encryptAES(req.content);

    if (ComHelper.isEmptry(req.title) && ComHelper.isEmptry(req.content)) {
      return new ResultPageList<YYListInfo>();
    }

    let list = await this.api.get<ResultPageList<YYListInfo>>(
      '/api/YY1/FilterList',
      req,
      false
    );

    // list.lstInfo.forEach(info => {
    //   info.title = CryptoHelper.decryptAES(info.title);
    // });

    return list;
  }

  // 获取YY1信息
  async getByID(req: IDReq, showLoader: boolean = true): Promise<ResultInfo<YYInfo>> {
    let item = await this.api.get<ResultInfo<YYInfo>>(
      '/api/YY1/GetByID',
      req,
      showLoader
    );

    // item.info.title = CryptoHelper.decryptAES(item.info.title);
    // item.info.content = CryptoHelper.decryptAES(item.info.content);

    return item;
  }

  // 修改YY1权重
  async modifyRight(req: YYModifyRightReq): Promise<ResultInfo<boolean>> {
    return await this.api.postReq<ResultInfo<boolean>>(
      '/api/YY1/ModifyRight',
      req,
      false
    );
  }
}
